//
//  HYMeetingDetailVC.m
//  Booking
//
//  Created by Duntech on 2018/4/20.
//  Copyright © 2018年 Duntech. All rights reserved.
//

#import "HYMeetingDetailVC.h"
#import "HYImageTableViewCell.h"
#import "HYMeetingScheduleVC.h"
#import "HYMeetingInfoCell.h"
#import "HYMeetingRoomInfoModel.h"
#import "HYTextFieldCellModel.h"
#import "HYTextFieldTableViewCell.h"
#import "HYRoomDetailModel.h"

@interface HYMeetingDetailVC ()

/** dataSource */
@property (nonatomic,strong) HYTableViewDataSource *dataSource;
/** delegate */
@property (nonatomic,strong) HYTableViewDelegate *delegate;
/** dataSets数据源 */
@property (nonatomic,strong) NSMutableArray *dataSetsArray;
@property (nonatomic,strong) NSMutableArray *sectionArray;
@property (nonatomic,strong) UITableView *tableView;
@property (nonatomic,strong) UIButton *backBtn;
@property (nonatomic,strong) UIButton *confirmBtn;

@end

@implementation HYMeetingDetailVC

- (void)viewDidLoad {
    
    [super viewDidLoad];
    self.fd_prefersNavigationBarHidden = YES;
    self.view.backgroundColor = KAPP_WHITE_COLOR;
    KAdjustsScrollViewInsets_NO(self, self.tableView);
    [self setupSubviews];
    [self registerTableViewCell];
    [self setupData];
}

#pragma mark - setStatusBar
- (UIStatusBarStyle)preferredStatusBarStyle {
    
    return UIStatusBarStyleDefault;
}

- (void)setupSubviews{
    
    self.dataSource.dataSource = self.dataSetsArray;
    self.delegate.dataSource = self.dataSetsArray;
    [self.view addSubview:self.tableView];
    [self.view addSubview:self.confirmBtn];
    [self.view addSubview:self.backBtn];
    
    [_backBtn mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.left.equalTo(self.view).offset(10 * WIDTH_MULTIPLE);
        make.size.mas_equalTo(CGSizeMake(30 * WIDTH_MULTIPLE, 30 * WIDTH_MULTIPLE));
        make.top.equalTo(self.view).offset(KSTATUSBAR_HEIGHT);
    }];
    
    [_confirmBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.bottom.equalTo(self.view).offset(-20 * WIDTH_MULTIPLE);
        make.left.equalTo(self.view).offset(20 * WIDTH_MULTIPLE);
        make.height.mas_equalTo(50 * WIDTH_MULTIPLE);
    }];
    
    [_tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.equalTo(self.view);
        make.bottom.equalTo(self.confirmBtn.mas_top).offset(-10);
    }];
}

- (void)setupData{
  
    NSMutableArray *sectionArray = [NSMutableArray array];
    HYImageCellModel *imageCellModel = [HYImageCellModel new];
    imageCellModel.cellIdientifier = @"HYImageTableViewCell";
    imageCellModel.cellHeight = 230 * WIDTH_MULTIPLE;
    imageCellModel.imgUrl = self.roomModel.imgUrl;
    imageCellModel.isBgImg = YES;
    [sectionArray addObject:imageCellModel];
    
    HYMeetingRoomInfoModel *meetingRoomInfoModel = [HYMeetingRoomInfoModel new];
    meetingRoomInfoModel.cellIdientifier = @"HYMeetingInfoCell";
    meetingRoomInfoModel.cellHeight = 250 * WIDTH_MULTIPLE;
    meetingRoomInfoModel.roomName = self.roomModel.name;
    meetingRoomInfoModel.floorNo = self.roomModel.floorName;
    meetingRoomInfoModel.buildingName = self.roomModel.buildName;
    meetingRoomInfoModel.city = self.roomModel.cityName;
    meetingRoomInfoModel.capacity = self.roomModel.capacity;
    meetingRoomInfoModel.tel = self.roomModel.tel;
    meetingRoomInfoModel.device = self.roomModel.type;
    [sectionArray addObject:meetingRoomInfoModel];
    [self.dataSetsArray addObject:sectionArray];
    [self.tableView reloadData];
}

- (void)registerTableViewCell{
    
    [self.tableView registerClass:[HYImageTableViewCell class] forCellReuseIdentifier:@"HYImageTableViewCell"];
    [self.tableView registerClass:[HYMeetingInfoCell class] forCellReuseIdentifier:@"HYMeetingInfoCell"];
    [self.tableView registerClass:[HYTextFieldTableViewCell class] forCellReuseIdentifier:@"HYTextFieldTableViewCell"];
    [self.delegate setHeaderHeightBlock:^CGFloat(UITableView *tableView, NSInteger section) {
        if (section == 0) {
            return 0;
        }
        return 10 * WIDTH_MULTIPLE;
    }];
    
}

#pragma mark - action
- (void)confirmBtnAction{
    if ([self.roomModel.status intValue] == 1) {
        HYMeetingScheduleVC *meetingScheduleVC = [HYMeetingScheduleVC new];
        meetingScheduleVC.roomModel = self.roomModel;
        meetingScheduleVC.scheduleType = MeetingRoomSchedule;
        meetingScheduleVC.meetingDate = self.meetingDate;
        meetingScheduleVC.startTime = self.startTime;
        meetingScheduleVC.endTime = self.endTime;
        [self.navigationController pushViewController:meetingScheduleVC animated:YES];
    }
    else{
        [JRToast showWithText:NSLocalizedString(@"unavailableTips", nil)];
    }
}
   

#pragma mark - lazyload
- (HYTableViewDataSource *)dataSource{
    
    if (!_dataSource) {
        _dataSource = [HYTableViewDataSource new];
    }
    return _dataSource;
}

- (NSMutableArray *)dataSetsArray{
    
    if (!_dataSetsArray) {
        _dataSetsArray = [NSMutableArray array];
    }
    return _dataSetsArray;
}

- (NSMutableArray *)sectionArray{
    
    if (!_sectionArray) {
        _sectionArray = [NSMutableArray array];
    }
    return _sectionArray;
}

- (HYTableViewDelegate *)delegate{
    
    if (!_delegate) {
        _delegate = [HYTableViewDelegate new];
    }
    return _delegate;
}

- (UITableView *)tableView{
    
    if (!_tableView) {
        _tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
        _tableView.backgroundColor = KAPP_WHITE_COLOR;
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableView.delegate = self.delegate;
        _tableView.dataSource = self.dataSource;
    }
    return _tableView;
}

- (UIButton *)backBtn{
    
    if (!_backBtn) {
        
        _backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_backBtn setImage:[UIImage imageNamed:@"back"] forState:UIControlStateNormal];
        [_backBtn addTarget:self action:@selector(backBtnAction) forControlEvents:UIControlEventTouchUpInside];
    }
    return _backBtn;
}

- (UIButton *)confirmBtn{
    
    if (!_confirmBtn) {
        
        _confirmBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_confirmBtn setBackgroundColor:KAPP_THEME_COLOR];
        [_confirmBtn setTitle:NSLocalizedString(@"book", nil) forState:UIControlStateNormal];
        [_confirmBtn setTitleColor:KAPP_WHITE_COLOR forState:UIControlStateNormal];
        _confirmBtn.titleLabel.font = KFitFont(16);
        [_confirmBtn addTarget:self action:@selector(confirmBtnAction) forControlEvents:UIControlEventTouchUpInside];
        _confirmBtn.layerCornerRadius = 4;
    }
    return _confirmBtn;
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end
